package com.stylefeng.guns.modular.platform.controller;
 
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.web.bind.annotation.RequestParam;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.platform.model.BuyerDemand;
import com.stylefeng.guns.modular.platform.model.SellerDemand;
import com.stylefeng.guns.modular.platform.service.ISellerDemandService;

/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2018-07-13 19:10:46
 */
@Controller
@RequestMapping("/sellerDemand")
public class SellerDemandController extends BaseController {

    private String PREFIX = "/platform/sellerDemand/";

    @Autowired
    private ISellerDemandService sellerDemandService;

    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "sellerDemand.html";
    }

    /**
     * 跳转到添加
     */
    @RequestMapping("/sellerDemand_add")
    public String sellerDemandAdd() {
        return PREFIX + "sellerDemand_add.html";
    }

    /**
     * 跳转到修改
     */
    @RequestMapping("/sellerDemand_update/{sellerDemandId}")
    public String sellerDemandUpdate(@PathVariable Integer sellerDemandId, Model model) {
        SellerDemand sellerDemand = sellerDemandService.selectById(sellerDemandId);
        model.addAttribute("item",sellerDemand);
        LogObjectHolder.me().set(sellerDemand);
        return PREFIX + "sellerDemand_edit.html";
    }

    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(SellerDemand sellerDemand) {
    	EntityWrapper<SellerDemand> wp =null;
    	if(StringUtils.isNotBlank(sellerDemand.getAppName())){
    		wp= new EntityWrapper<SellerDemand>();
    		wp.like("app_name", sellerDemand.getAppName());
    	}
        return sellerDemandService.selectList(wp);
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(SellerDemand sellerDemand) {
        sellerDemandService.insert(sellerDemand);
        return SUCCESS_TIP;
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer sellerDemandId) {
        sellerDemandService.deleteById(sellerDemandId);
        return SUCCESS_TIP;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(SellerDemand sellerDemand) {
        sellerDemandService.updateById(sellerDemand);
        return SUCCESS_TIP;
    }

    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{sellerDemandId}")
    @ResponseBody
    public Object detail(@PathVariable("sellerDemandId") Integer sellerDemandId) {
        return sellerDemandService.selectById(sellerDemandId);
    }
}
